//引入
import { Index } from 'index-model.js';
var index = new Index();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var source_num = wx.getStorageSync('source_num');
    this.setData({
      'source_num': source_num,
      'isNotFound': true,
      'isShowSourceCodeView':false,
    })
    this.data.source_num = source_num;//保存到全局
    this._loadData();
  },
  _loadData: function () {
    //轮播图
    var data = index.getBannerData((res) => {//回调
      //数据绑定
      this.setData({
        'bannerArray': res
      })
    });
    //商品信息
    index.getCommodityData(this.data.source_num,(data)=>{
      var commodity = data
      if (commodity === undefined) {
        commodity = []
      }
      this.setData({
        'commodityArray': commodity,
        'isNotFound': commodity.length <= 0,
        'isShowSourceCodeView':true,
      })
      
    });
    //产品信息
    index.getBatchData(this.data.source_num, (data) => {
      this.setData({
        'batchArray': data
      })
    });
    //修剪
    index.getSourceData(this.data.source_num, (data) => {
      var prune = data.prune
      if (prune === undefined){
        prune = []
      }
      this.setData({
        'pruneArray': prune,
        'pruneFound': prune.length > 0,
      })
    });
    //除草
    index.getSourceData(this.data.source_num, (data) => {
      var pesticide = data.pesticide
      if (pesticide === undefined) {
        pesticide = []
      }
      this.setData({
        'pesticideArray': pesticide,
        'pesticideFound': pesticide.length > 0,
      })
    });
    //施肥
    index.getSourceData(this.data.source_num, (data) => {
      var manure = data.manure
      if (manure === undefined) {
        manure = []
      }
      this.setData({
        'manureArray': manure,
        'manureFound': manure.length > 0,
      })
    });
  },
})